package model.utils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

public class FileUtils {
	
	private static String path = "src\\xml\\";
	
	public static void writeFile(String fileName, String text){
		String fullName = path + fileName;
		try {
			PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(fullName)));
			writer.write(text);
			writer.flush();
			writer.close();
		} catch (Exception e) {
			System.err.println("Se produjo un error al escribir el archivo: " + e.getMessage());
		}
	}
	
	public static String readFile(String fileName){
		String fullName = path + fileName; 
		try {
			int length = (int)new File(fullName).length();
			BufferedReader reader = new BufferedReader(new FileReader(fullName));
			char[] buffer = new char[length]; 
			reader.read(buffer);		
			return new String(buffer); 
		} catch (Exception e) {
			System.err.println("Se produjo un error al leer el archivo: " + e.getMessage());
		}
		return ""; 
	}
}
